package com.xnyzc.lhy.task.task.activity;

import com.xnyzc.lhy.task.fegin.activity.QuartzActivityStatisticsService;
import com.xnyzc.lhy.task.fegin.punishment.QuartzPunishmentStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: haoyfa
 * @Date: 2019-12-29
 * @Description 活动定时任务
 */

@Slf4j
@Component("quartzActivityStatistics")
public class QuartzActivityStatistics {
    @Autowired
    private QuartzActivityStatisticsService quartzActivityStatisticsService;

    /**
     * 更新活动状态，包括活动定义和活动周期
     * 定时任务调用，每隔1分钟调用1次
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    public void updateActivityStatusTask() {

        log.info("===========开始更新活动状态==========");
        quartzActivityStatisticsService.updateActivityStatus();
        log.info("===========结束更新活动状态===========");
    }

    /**
     * 活动周期完成
     * 定时任务调用，每天凌晨4点执行
     *
     * @return
     */
    @Scheduled(cron = "0 0 4 * * ?")
    public void completeActivityPeriod() {

        log.info("===========开始活动周期完成==========");
        quartzActivityStatisticsService.completeActivityPeriod();
        log.info("===========结束活动周期完成===========");
    }

    /**
     * 活动周期结算
     * 定时任务调用，每隔1分钟调用1次
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    public void calActivityRewardTask() {

        log.info("===========开始活动周期结算==========");
        quartzActivityStatisticsService.calActivityPeriodReward();
        log.info("===========结束活动周期结算===========");
    }
}
